package com.neoz.demo.javabasic;

import java.io.*;
import java.util.*;

import com.neoz.demo.javabasic.util.CmdUtil;

public class ObjectSerialize {

	public static void main(String[] args) throws IOException,
			ClassNotFoundException {
		String fileName = "d:\\ObjectSerialize.txt";
		CmdUtil.printTitle("Serialize to file " + fileName);
		FileOutputStream fs = new FileOutputStream(fileName);
		ObjectOutputStream os = new ObjectOutputStream(fs);
		os.writeObject(new Date());
		os.close();

		CmdUtil.printTitle("Unserialize from file");
		FileInputStream fis = new FileInputStream(fileName);
		ObjectInputStream ois = new ObjectInputStream(fis);
		Date dt = (Date) ois.readObject();
		ois.close();
		CmdUtil.print(dt + "");
	}

}
